/*
 *  Copyright (C) <2009>  Pavel Vakeš <pavel.vakes@gmail.com>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef MessagesView_HEADER
#define MessagesView_HEADER

#include <QTreeView>


class MessagesView : public QTreeView
{
Q_OBJECT

public:
  /**
  * Constructor of view
  * @param parent the parent of this object
  **/
  MessagesView(QWidget *parent = 0);

  /**
  * Default destructor
  **/
  virtual ~MessagesView();

  /**
   * Creates rects in widget coordinates for the model
   */
  void calculateRects();

  QRect visualRect ( const QModelIndex & index ) const;

protected:
  /**
  * Call when the view is resized
  * @param event the resize event
  **/
  void resizeEvent(QResizeEvent * event);

  /**
  * Call when a mouse move event is catch
  * @param event the mouse event
  **/
  void mouseMoveEvent(QMouseEvent *event);

  /**
   * Call when a mouse move event is catch
   * @param event the mouse event
   **/
  void mousePressEvent(QMouseEvent *event);

  /**
  * Call when cursor leave the widget
  * @param event the leave event
  **/
  void leaveEvent(QEvent *event);

  /**
  * Move the cursor in the way describe by cursorAction
  * @param cursorAction the cursor action
  **/
  QModelIndex moveCursor(CursorAction cursorAction,Qt::KeyboardModifiers );

  /**
  * Call when the view is paint
  * @param event the paint event
  **/
  void paintEvent(QPaintEvent *event);

  /**
  * Paint a header item
  * @param painter the painter used to paint
  * @param itemRect the rect where the item will be paint
  * @param index the QModelIndex that represent the item to paint
  **/
//  void paintHeaderItem(QPainter &painter,const QRect &itemRect,const QModelIndex &index);

  /**
  * Paint an item in the view by using the delegate
  * @param painter the painter used to paint
  * @param itemRect the rect where the item will be paint
  * @param index the QModelIndex that represent the item to paint
  **/
  void paintItem(QPainter &painter,const QRect &itemRect,const QModelIndex &index);

  /**
  * Return an index at the position "point" if exist otherwise return a default
  * constructed value of QModelIndex
  * @param point the point where we will looking for an item
  **/
  QModelIndex indexAt(const QPoint& point) const;

  static const int VIEW_TOP_OFFSET = 10;
  static const int COL_MARGIN_SIDE = 10;
  static const int COL_STATUS_WIDTH = 300;
  static const int COL_TIME_WIDTH = 50;
  static const int ROW_HEIGHT = 42;

private:
  ///The hovered index
  QPersistentModelIndex m_hoveredIndex;
  QHash<QModelIndex,QRect> itemRects;
};

#endif
